<?php

namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\DormRatingMain;

/**
 * Class DormRatingMainTransformer.
 *
 * @package namespace App\Transformers;
 */
class DormRatingMainTransformer extends TransformerAbstract
{
    /**
     * Transform the DormRatingMain entity.
     *
     * @param \App\Models\DormRatingMain $model
     *
     * @return array
     */
    public function transform(DormRatingMain $model)
    {
        return [
            'id'         => (int) $model->id,
            'company' => $model->company,
            'user_id'         => $model->user_id,
            'username'         => optional($model->user)->name,
            'period_id'         => $model->period_id,
            'period_name'         => optional($model->period)->name,
            'dorm_id'         => $model->dorm_id,
            'dorm_code'         => optional($model->dorm)->code,
            'get_score'         => $model->get_score,
            'total_score'         => $model->total_score,
            'score_rate'         => $model->total_score > 0 ? round($model->get_score / $model->total_score * 100, 2) : 0,
            'remark'         => $model->remark,
            /* place your other model properties here */

            'created_at' => $model->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $model->updated_at->format('Y-m-d H:i:s'),
        ];
    }
}
